package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/22/13
 * Time: 11:52 PM
 * To change this template use File | Settings | File Templates.
 */
public class BookLibrary {
    private HashMap<String, Book> books;
    private PrintStream printStream;

    public BookLibrary(HashMap<String, Book> books, PrintStream printStream) {
        this.books = books;
        this.printStream = printStream;
    }

    public Book getBook(String bookName) {
        return books.get(bookName);

    }

    public boolean reserveBook(String bookName) {
        Book b = this.getBook(bookName);
        if (b != null && !b.isReserved()) {
            String message = getThankYouMessage();
            b.reserve();
            printStream.println(message);
            return true;
        } else {
            printStream.println("Sorry we don't have that book yet.");
            return false;
        }
    }

    private String getThankYouMessage() {
        return "Thank You! Enjoy the book.";
    }


    public void showBooks() {
        for(String book: books.keySet()){
            printStream.println(book);
        }
    }
}
